package com.neusoft.reactor.jdkflow;

import java.util.concurrent.SubmissionPublisher;

/**
 * @author lichunlong lcl253137@alibaba-inc.com
 * @desc Reactive JDK框架默认实现
 * @date 2023-01-17
 */
public class FlowDemo {

    public static void main(String[] args) throws InterruptedException {
        SubmissionPublisher<String> publisher = new SubmissionPublisher<>();
        try (publisher) {
            // 建立发布者、订阅者之间的关系
            publisher.subscribe(new StringSubscriber("A"));
            publisher.subscribe(new StringSubscriber("B"));
            publisher.subscribe(new StringSubscriber("C"));

            // Action: 发布数据
            publisher.submit("Hello World!");
            publisher.submit("Hello Reactive!");
        }

        // 上述代码为异步操作，main主线程阻塞现场
        Thread.currentThread().join(1000L);
    }

}
